<?xml version="1.0" encoding="UTF-8" ?>

<!--
    Document   : atom2tree-rdf.xsl
    Created on : April 30, 2006, 7:37 AM
    Author     : alex
    Description:
        Purpose of transformation follows.
-->

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:atom="http://www.w3.org/2005/Atom"
   xmlns:atomic="http://www.atomojo.org/O/atomic/"
   xmlns:atompub="http://www.w3.org/2007/app">

<xsl:template match="atompub:service">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:atomic="http://www.atomojo.org/O/atomic/">
      <xsl:text>&#xa;</xsl:text>
      <rdf:Seq rdf:about="http://www.atomojo.org/O/atomic/services">
         <rdf:li rdf:resource="{@xml:base}"/>
      </rdf:Seq>
      <xsl:text>&#xa;</xsl:text>
      <rdf:Description rdf:about="{@xml:base}" atomic:id="{@xml:base}" atomic:title="{@xml:base}" atomic:type="service"/>
      <xsl:text>&#xa;</xsl:text>
      <rdf:Seq rdf:about="{@xml:base}">
         <xsl:text>&#xa;</xsl:text>
         <xsl:for-each select="atompub:workspace">
            <rdf:li rdf:resource="{@client-id}"/>
            <xsl:text>&#xa;</xsl:text>
         </xsl:for-each>
      </rdf:Seq>
      <xsl:text>&#xa;</xsl:text>
      <xsl:apply-templates select="atompub:workspace"/>
   </rdf:RDF>
</xsl:template>

<xsl:template match="atompub:workspace">
   <rdf:Description rdf:about="{@client-id}" atomic:id="{../@xml:base}/{position()}" atomic:title="{@title}{atom:title}" atomic:type="workspace"/>
   <xsl:text>&#xa;</xsl:text>
   <rdf:Seq rdf:about="{@client-id}">
      <xsl:text>&#xa;</xsl:text>
      <xsl:for-each select="atompub:collection[@level='0']">
         <rdf:li rdf:resource="{@href}"/>
         <xsl:text>&#xa;</xsl:text>
      </xsl:for-each>
   </rdf:Seq>
   <xsl:text>&#xa;</xsl:text>
   <xsl:apply-templates select="atompub:collection"/>
   <xsl:text>&#xa;</xsl:text>
</xsl:template>

<xsl:template match="atompub:collection">
   <xsl:variable name="next" select="string(number(@level)+1)"/>
   <xsl:variable name="current-href" select="@href"/>
   <rdf:Description rdf:about="{@href}" atomic:id="{@href}" atomic:title="{@title}{atom:title}" atomic:type="collection"/>
   <xsl:text>&#xa;</xsl:text>
   <rdf:Seq rdf:about="{@href}">
      <xsl:text>&#xa;</xsl:text>
      <xsl:for-each select="../atompub:collection[@level=$next and starts-with(@href,$current-href)]">
         <rdf:li rdf:resource="{@href}"/>
         <xsl:text>&#xa;</xsl:text>
      </xsl:for-each>
   </rdf:Seq>
   
</xsl:template>


</xsl:transform>
